package com.wuliu.servlet;

import com.wuliu.dao.NewsClassDAO;
import com.wuliu.dao.NewsDAO;
import com.wuliu.dao.impl.NewsClassDAOImpl;
import com.wuliu.dao.impl.NewsDAOImpl;
import com.wuliu.model.News;
import com.wuliu.model.NewsClass;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/page10")
public class NewsInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        NewsClassDAO newsClassDAO = new NewsClassDAOImpl();
        List<NewsClass> newsClasses = newsClassDAO.findAll();
        req.setAttribute("newsClasses", newsClasses);

        int id=Integer.valueOf(req.getParameter("id"));
        NewsDAO newsDAO = new NewsDAOImpl();
        News news=(News) newsDAO.findById(Integer.valueOf(id));
        req.setAttribute("news",news);
        req.getRequestDispatcher("/WEB-INF/view/news_info.jsp").forward(req,resp);

    }
}
